home *** CD-ROM | disk | FTP | other *** search
/ SuperHack / SuperHack CD.bin / CODING / GRAPHICS / VOXRAY.ZIP / VOXSETUP.CPP < prev    next >
Encoding:
C/C++ Source or Header  |  1995-10-19  |  4.9 KB  |  194 lines

  1. #include "ray.h"
  2. #include "resnames.h"
  3. #include "globals.h"
  4. #include "voxel.h"
  5. #include "rayfile.h"
  6. #include "waves.h"
  7. #include "prevarr.h"
  8. #include "scrconf.h"
  9. #include "gentree.h"
  10. #include "sprvox.h"
  11. #include "verttan.h"
  12.  
  13. #define VOX_PAL_FILE "vox.pal"
  14. #define START_DIS VOXEL_SPEED_SCALE
  15. #define START_HEIGHT 3
  16.  
  17. BOOL voxel_running=FALSE;
  18. PUCHAR pal_save;
  19. //long old_px, old_py, old_pv_angle; No longer needed as engines use one coordinate system
  20.  
  21. void Setup_G_Table();
  22. void Setup_Y_Jumps();
  23. void Setup_Alt_Scaler();
  24. void Setup_H_Table();
  25. void Setup_Change_Table();
  26.  
  27. inline void Del_Alt_Scaler() {
  28.   for (short i=0; i<DIST_MAX; i++)
  29.     DelPtr(alt_scaler[i]);
  30.   DelPtr(alt_scaler);
  31. }
  32.  
  33. void Close_Voxel()
  34. {
  35.    if (!voxel_running) {
  36.       return;
  37.    } /* endif */
  38.    DelPtr(g_table);
  39.    DelPtr(y_jumps);
  40.    Del_Alt_Scaler();
  41.    Close_Waves();  
  42.    voxel_running=FALSE;
  43. }
  44.  
  45. void Init_Voxel()
  46. {
  47. DIST_SCALER=START_DIS;
  48. V_Set_Dist_Scale(START_HEIGHT);
  49. Setup_Voxel_Tables();
  50. Setup_Waves();
  51. voxel_running=TRUE;
  52. Init_Vox_Sprite_Table();
  53. }
  54.  
  55. void Setup_Voxel_Tables()
  56. {
  57.    Setup_Y_Jumps();
  58.    Setup_G_Table();
  59.    Setup_Alt_Scaler();
  60.    Setup_H_Table();
  61.    Setup_Change_Table();
  62. }
  63.  
  64.  
  65. void Setup_Y_Jumps()
  66. {
  67.    y_jumps=(PULONG)NewPtr(Get_Phys_Screen_Height() * sizeof(ULONG));
  68.  
  69. if (Get_Phys_Orientation()>0) {
  70.    ULONG cur_offset=0;
  71.    for (USHORT cur_y=0; cur_y<Get_Phys_Screen_Height(); cur_y++) {
  72.       y_jumps[cur_y]=cur_offset;
  73.       cur_offset+=(ULONG)Get_Phys_Screen_Width();
  74.    } /* endfor */
  75. } else {
  76.    ULONG cur_offset=(Get_Phys_Screen_Height()-1)*Get_Phys_Screen_Width();
  77.    for (USHORT cur_y=0; cur_y<Get_Phys_Screen_Height(); cur_y++) {
  78.       y_jumps[cur_y]=cur_offset;
  79.       cur_offset-=(ULONG)Get_Phys_Screen_Width();
  80.    }
  81. }
  82.  
  83. }
  84.  
  85. void Setup_H_Table() {
  86.    h_table=(PLONG)NewPtr(Get_Phys_Screen_Height() *2 * MAX_TABLED_HC_INTP*sizeof(long));
  87.  
  88.    short cur_height_diff, cur_r_length;
  89.    short real_height_diff;
  90.  
  91.    for (cur_height_diff=0; cur_height_diff<(Get_Phys_Screen_Height()*2); cur_height_diff++) {
  92.  
  93.       real_height_diff=cur_height_diff-Get_Phys_Screen_Height();
  94.  
  95.          // set 0 manually as loop cause div by 0
  96.          h_table[cur_height_diff*MAX_TABLED_HC_INTP]=0;
  97.          for (cur_r_length=1; cur_r_length<MAX_TABLED_HC_INTP; cur_r_length++) {
  98.             h_table[MAX_TABLED_HC_INTP*cur_height_diff+cur_r_length]=(long)
  99.                (((long)real_height_diff << HEIGHT_CHANGE_SHIFT) /
  100.                (long)cur_r_length);
  101.          } /* endfor */
  102.       } /* endif */
  103.  
  104. }
  105.  
  106. void Setup_Change_Table() {
  107.    vox_change_table=(PVOID)NewPtr(Get_Phys_Screen_Width()*HCP_SIZE);
  108. }
  109.  
  110. void Setup_G_Table()
  111. {
  112.    g_table=(PSHORT)NewPtr((Get_Phys_Screen_Width()+1)*COLOR_DIFF_COUNT*sizeof(short));
  113.  
  114.    short cur_col_diff, cur_r_length;
  115.    short real_col_diff;
  116.  
  117.    for (cur_col_diff=0; cur_col_diff<COLOR_DIFF_COUNT; cur_col_diff++) {
  118.  
  119.       real_col_diff=cur_col_diff-G_TABLE_ADJUST;
  120.  
  121.       // is this a color diff there is posible interpolation for
  122.       if ((real_col_diff<MAX_INT_LIGHT_DIFF)&&(real_col_diff>MIN_INT_LIGHT_DIFF)) {
  123.  
  124.          // set 0 manually as loop cause div by 0
  125.          g_table[cur_col_diff]=0;
  126.          for (cur_r_length=1; cur_r_length<(Get_Phys_Screen_Width()+1); cur_r_length++) {
  127.             g_table[COLOR_DIFF_COUNT*cur_r_length+cur_col_diff]=(short)
  128.                (((long)real_col_diff << LIGHT_FP_SHIFT) /
  129.                (long)cur_r_length);
  130.          } /* endfor */
  131.       } else {
  132.          for (cur_r_length=0; cur_r_length<(Get_Phys_Screen_Width()+1); cur_r_length++) {
  133.             g_table[COLOR_DIFF_COUNT*cur_r_length+cur_col_diff]=0;
  134.          } /* endfor */
  135.       } /* endif */
  136.  
  137.    } /* endfor */
  138.  
  139. }
  140.  
  141. void Setup_Alt_Scaler()
  142. {
  143.    short cur_dis;
  144.    short cur_alt;
  145.    long temp_calc;
  146.  
  147.    // allocate altitudes
  148.    alt_scaler=(PSHORT *)NewPtr(DIST_MAX * sizeof(PSHORT));
  149.    for (cur_dis=0; cur_dis<DIST_MAX; cur_dis++) {
  150.       alt_scaler[cur_dis]=(PSHORT)NewPtr(ALT_MAX * sizeof(SHORT));
  151.    } /* endfor */
  152.  
  153.    // get screen heights by altitudes
  154.    for (cur_dis=1; cur_dis<DIST_MAX; cur_dis++) {
  155.       for (cur_alt=0; cur_alt<ALT_MAX; cur_alt++) {
  156.          temp_calc=(LONG)(ALT_MAX-(cur_alt+1));
  157.          temp_calc*=HEIGHT_SCALER;
  158.          temp_calc*=(y_trans/(cur_dis*DIST_SCALER));
  159.          temp_calc>>=SHIFT;
  160.          alt_scaler[cur_dis][cur_alt]=(SHORT)temp_calc;
  161.       } /* endfor */
  162.    } /* endfor */
  163.  
  164. }
  165.  
  166. void V_Recalc_Alts()
  167. {
  168. if (voxel_running) {
  169.    Del_Alt_Scaler();
  170.    Setup_Alt_Scaler();
  171. }
  172. }
  173.  
  174. void V_Recalc_Screen() {
  175.    if (voxel_running) {
  176.       DelPtr(y_jumps);
  177.       DelPtr(g_table);
  178.       DelPtr(h_table);
  179.       DelPtr(vox_change_table);
  180.       Setup_Y_Jumps();
  181.       Setup_G_Table();
  182.       Setup_H_Table();
  183.       Setup_Change_Table();
  184.    }
  185. }
  186.  
  187. void V_Recalc_Length() {
  188.    if (voxel_running) {
  189.       v_horiz_length=WINDOW_WIDTH;
  190.    }
  191. }
  192.  
  193.  
  194.